<%@ page language="java" import="java.util.*,com.shms.entity.*,com.shms.service.*,com.shms.service.impl.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>编辑学生信息</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="css/backmain.css" type="text/css"></link>
	<link rel="stylesheet" href="css/backeditor.css" type="text/css"></link>
	<script src="js/time/calendar3.js" type="text/javascript"></script>
	<script type='text/javascript' src='dwr/engine.js'></script>
	<script type='text/javascript' src='dwr/interface/HomeService.js'></script>
	<script type='text/javascript' src='dwr/interface/BuildService.js'></script>
	<script type='text/javascript' src='dwr/interface/ClassService.js'></script>
	<script type='text/javascript' src='dwr/util.js'></script>
	<script type="text/javascript">		
		//根据楼号获取对应的宿舍号数据
		function getHome(){
			HomeService.queryHomeByBid(dwr.util.getValue("buildno"), homescallback);
		}
		
		//getHome的回调方法
		function homescallback(home){
			if(home != null){
				//移除所有的id为homeno下拉框的数据
				dwr.util.removeAllOptions("homeno"); 
				//为id为homeno下拉框的添加数据
				dwr.util.addOptions("homeno", home, "hid", "hno");
				//如果传来宿舍号和楼号均不为0，即编辑宿舍成绩，宿舍号显示为对应下拉项
				if(<%=request.getAttribute("buildbno")%> != 0 && <%=request.getAttribute("homehno")%> != 0){
					dwr.util.setValue("homeno", <%=request.getAttribute("homehno")%>);
				}
			}
		}
		
		//获取宿舍楼号,班级和性别数据
		function getInfo(){
			BuildService.queryAllBno(buildscallback);
			ClassService.queryAllCname(classscallback);
			
			var sexValue = document.getElementById("sex").value;
			if(sexValue == "")
				document.getElementById("ssex").value = "男";
			else
	   			document.getElementById("ssex").value = sexValue;
	   		
	   		var type = <%=request.getAttribute("type")%>;
	   		if(type == 0){
	   			document.getElementById("sno").readOnly = "readonly";
	   		}
		}
		
		//getBuild的回调方法
		function buildscallback(build){
			if(build != null){
				//移除所有的id为buildno下拉框的数据
				dwr.util.removeAllOptions("buildno");      
				//为id为buildno下拉框的添加数据
				dwr.util.addOptions("buildno", build, "bid", "bname");
				//如果传来楼号为0，即新添加宿舍成绩
				if(<%=request.getAttribute("buildbno")%> == 0) {
					//为宿舍号下拉添加默认数据
					HomeService.queryHomeByBid(dwr.util.getValue("buildno"), homescallback);
				} else {
					//宿舍楼号下拉显示传来的对应的下拉项
					dwr.util.setValue("buildno", <%=request.getAttribute("buildbno")%>);
					//根据传来的宿舍楼号查询对应的宿舍号数据
					HomeService.queryHomeByBid(<%=request.getAttribute("buildbno")%>, homescallback);
				}				
			}
		}
		
		function classscallback(classes){
			if(classes != null){
				dwr.util.removeAllOptions("cname");
				dwr.util.addOptions("cname", classes, "cid", "cname");
				
				if(<%=request.getAttribute("classcname")%> != 0) {
					dwr.util.setValue("cname", <%=request.getAttribute("classcname")%>);
				}
			}
		}
	</script>
  </head>
  
  <body onload="getInfo()">
    <div class="right_div">
    	<div class="right_top">
    		<div class="titlebt1">编辑学生信息</div>
    	</div>
    	<div class="right_main">
    		<div><span class="inputmessage">${message}</span></div>
    		<form method="post" action="saveStudent.action">
    			<table class="add_table">
    				<tr>
    					<td width="3%">&nbsp;</td>
    					<td width="7%">学号<span class="required_info">*</span>：</td>
    					<td width="90%">
    						<input id="sno" name="shStudent.sno" type="text" class="input_text" value="${shStudent.sno}"/>
    					</td>
    				</tr>
    				<tr>
    					<td width="3%">&nbsp;</td>
    					<td width="7%">姓名<span class="required_info">*</span>：</td>
    					<td width="90%">
    						<input name="shStudent.sname" type="text" class="input_text" value="${shStudent.sname}"/>
    					</td>
    				</tr>
    				<tr>
    					<td>&nbsp;</td>
    					<td>性别<span class="required_info">*</span>：</td>
    					<td>
    						<input name="sex" type="hidden" id="sex" value="${shStudent.ssex}" />
    						<select id="ssex" name="shStudent.ssex" >
    							<option value="男">男</option>   
								<option value="女">女</option>
    						</select>
    					</td>
    				</tr> 
    				<tr>
    					<td>&nbsp;</td>
    					<td>班级<span class="required_info">*</span>：</td>
    					<td>
    						<select name="shStudent.cid" id="cname"></select>
    					</td>
    				</tr>  
    				<tr>
    					<td>&nbsp;</td>
    					<td>宿舍楼号<span class="required_info">*</span>：</td>
    					<td>
    						<select id="buildno" name="shStudent.bid" onchange="javascript:getHome();"></select>
    					</td>
    				</tr> 
    				<tr>
    					<td>&nbsp;</td>
    					<td>宿舍号<span class="required_info">*</span>：</td>
    					<td>
    						<select name="shStudent.hid" id="homeno"></select>
    					</td>
    				</tr> 
    				<tr>
    					<td>&nbsp;</td>
    					<td>&nbsp;</td>
    					<td>
    						<input type="hidden" name="shStudent.park1" value="${shStudent.park1}" />
    						<input type="hidden" name="shStudent.park2" />
    						<input type="hidden" name="shStudent.park3" />
    						<input type="reset" class="btn" value="重置">
    						<input type="submit" class="btn" value="保存">
    					</td>
    				</tr>
    			</table>
    		</form>
    	</div>
    </div>
  </body>
</html>
